package com.vg.config;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectInputStream.GetField;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;

import android.content.Context;

public class dulieu {

	static final String SAVE_STATE_FILE_NAME = "leve.txt";
	static final String SAVE_CHOILAI_FILE_NAME = "choilai.txt";
	static final String Save_Array = "arr.txt";

	private List<HashMap<String, String>> ListMaps = new ArrayList<HashMap<String, String>>();
	private String FileName = "CData";
	private String F_Path = "";

	public void writeListToFile(Context mContext,
			JSONArray jsonArr) {
		if (null == FileName)
			throw new RuntimeException("FileName is null!");
		FileOutputStream fos;
		try {
			fos = mContext.openFileOutput(FileName, mContext.MODE_PRIVATE);

			// FileOutputStream fos = new FileOutputStream(FileName);
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject(jsonArr);
			fos.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public JSONArray loadListFromFile(Context mconContext, JSONArray masterlistrev) {
		      if(null == FileName)
		          return null;
		     
		      File myfile =mconContext.getFileStreamPath(FileName);
		      try {
		            if(myfile.exists()){
		                  FileInputStream fis =mconContext.openFileInput(FileName);
		                  ObjectInputStream ois = new ObjectInputStream(fis);
		                  masterlistrev = (JSONArray) ois.readObject();
		                  fis.close();
		            }else {
		                  return null;
		            }
		       } catch (Exception e) {
		          e.printStackTrace();
		       }
		       return masterlistrev;
		      }
	
}
